const {
    Controller
} = require('uni-cloud-router')
const db = uniCloud.database();
const filesCollection =db.collection('user-id-files')
const classifyCollection =db.collection('user-id-files-classify')
const dbCmd = db.command
module.exports = class ClassifyController extends Controller {
	async hasClassify(){
		
	}
    async init() {
		
    }
	async remove(){
		const ctx=this.ctx
		const data=this.ctx.data
		let  {id}=data
		const {total:classifyCount} =await classifyCollection.where({
			parent_id:id
		}).count();
		if(classifyCount>0){
			this.throw('HAS_CLASSIFY', '目录有子目录');
		}
		
		const {total:filesCount} = await filesCollection.where({
			classify:id
		}).count();
		if(filesCount>0){
			this.ctx.throw('HAS_FILES', '目录内有文件');
		}
		
		const {deleted:count}=await classifyCollection.where({
			_id:id
		}).remove();
		return {count};
	}
}
